package com.littlerpc.protocol.net.common;


import com.littlerpc.protocol.net.netty.client.NettyClient;

/**
 *
 * @author ChengPeng
 * @date 2017/6/18
 */
public enum NetProtocolClientEmum {

    /**
     * NETTY
     */
    NETTY(NettyClient.class);


    public final Class<? extends RpcClient> serverClass;

    private NetProtocolClientEmum(Class<? extends RpcClient> serverClass) {
        this.serverClass = serverClass;
    }

    private Class<? extends RpcClient> value() {
        return serverClass;
    }

    /**
     *获取匹配的数据
     * @param protocol
     * @return
     */
    public static Class<? extends RpcClient> match(String protocol) {

        if(protocol == null || "".equals(protocol)) {
            return NETTY.value();
        }

        NetProtocolClientEmum[] services = NetProtocolClientEmum.values();
        for(NetProtocolClientEmum emum : services) {
            if(emum.name().equalsIgnoreCase(protocol)) {
                return emum.value();
            }
        }
        return NETTY.value();
    }

}
